<template>
  <view :class="['login-container', size]">
    <image class="bg" src="@/static/image/login_bg.png"></image>
    <div class="content">
      <div class="change-box" @click="changeSize">
        <image class="change_icon w-16 h-12" src="@/static/image/change_icon.png"></image>
        <span>{{ size ? '无障碍模式' : '标准模式'}}</span>
      </div>
      <div class="login-title font-32">系统门户</div>
      <div class="sub-title font-18">象山县工程建设项目数字化评审应用系统</div>
      <div class="login-form">
        <div class="login-form-item">
          <image class="w-16 h-16" src="@/static/image/user.png"></image>
          <u-input v-model="loginForm.username" placholder="请输入账号"></u-input>
        </div>
        <div class="login-form-item">
          <image class="w-14 h-16" src="@/static/image/lock.png"></image>
          <u-input v-model="loginForm.password" :type="type" placholder="请输入密码"></u-input>
        </div>
        <div class="code-item">
          <div>
            <div class="login-form-item">
              <image class="w-14 h-16" src="@/static/image/lock.png"></image>
              <u-input v-model="loginForm.password" placholder="请输入验证码"></u-input>
            </div>
          </div>
          <div class="code"></div>
        </div>
        <div class="button-item font-18" @click="login">
          登录
        </div>
      </div>
    </div>
  </view>
</template>

<script>
// 引入crypto-js库
import Crypto from '../../common/crypto.js';
export default{
  data(){
    return {
      type: 'password',
      loginForm: {
        username: '',
        password: ''
      }
    }
  },
  computed: {
    size() {
      return this.$store.getters.getSize
    }
  },
  onLoad(){
    uni.setStorageSync('userInfo', {})
    uni.setStorageSync('token', '')
  },
  methods: {
    changeSize(){
      this.$store.commit('SET_SIZE')
    },
    login() {
      this.$api.login({
        username: Crypto.encrypt(this.loginForm.username),
        password: Crypto.encrypt(this.loginForm.password)
      }).then(res => {
        console.log(res)
        uni.setStorageSync('userInfo', res)
        uni.setStorageSync('token', res.token)
        uni.reLaunch({
          url: '/pages/index/index'
        })
      }).catch(err => {
        console.log(err)
        uni.reLaunch({
          url: '/pages/index/index'
        })
      })
    }
  }
}
</script>

<style lang='scss'>
.login-container {
  position: relative;
  .button-item {
    height: 100rpx;
    margin-top: 100rpx;
    border-radius: 50rpx;
    opacity: 1;
    background: #2251F8;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    line-height: 100rpx;
    text-align: center;
  }
  .bg {
    position: absolute;
    left: -50px;
    top: -70px;
    width: 518px;
    height: 352px;
    opacity: 1;
  }
  .content {
    padding-top: 300px;
    .login-form {
      padding: 0 60rpx;
      .login-form-item {
        height: 100rpx;
        margin-top: 40rpx;
        border-radius: 22rpx;
        opacity: 1;
        background: #F3F6FF;
        padding: 0 40rpx;
        display: flex;
        align-items: center;
        image {
          margin-right: 20rpx;
        }
      }
    }
    .change-box {
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .login-title {
      font-family: PingFang SC;
      text-align: center;
      width: 100%;
      color: #2251F8;
      line-height: 72px;
    }
    .change_icon {
      margin-right: 10rpx;
    }
    .sub-title {
      color: #8B8B8B;
      line-height: 24px;
      text-align: center;
    }
  }
}
</style>
